home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Atlanta_1990 / Atlanta-Devcon.2 / AppShell / examples / projlist / ProjList.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-26  |  9.8 KB  |  394 lines

  1. /* projlist.c
  2.  * Copyright (C) 1990 Commodore-Amiga, Inc.
  3.  * written by David N. Junod
  4.  *
  5.  * maintain a list of projects
  6.  *
  7.  */
  8.  
  9. #include <libraries/appshell.h>    /* library structure definitions */
  10. #include <clib/appshell_protos.h>
  11. #include "projlist.h"        /* application structure definitions */
  12.  
  13. extern struct WBStartup *WBenchMsg;
  14.  
  15. /* Main processing loop */
  16. VOID main (int argc, char **argv)
  17. {
  18.  
  19.     HandleApp (argc, argv, WBenchMsg, Our_App);
  20. }
  21.  
  22. VOID ShowProjectIcon (struct AppInfo * ai, STRPTR cmd, struct TagItem * tl)
  23. {
  24.     struct ProjNode *pn;
  25.     struct DiskObject *dob = NULL;
  26.     struct Image *im = NULL;
  27.     struct Gadget *gad;
  28.     struct Window *win;
  29.     STRPTR name = NULL;
  30.     struct List *list;
  31.     struct Project *pi;
  32.  
  33.     /* default to the AppInfo Project structure */
  34.     pi = &(ai->ai_Project);
  35.  
  36.     /* see if there was a tag for a project list */
  37.     if (tl)
  38.     pi = (struct Project *) GetTagData (APSH_ProjInfo, (ULONG) pi, tl);
  39.  
  40.     /* get a pointer to our project list */
  41.     list = &(pi->p_ProjList);
  42.  
  43.     /* set the appropriate state of the select and remove function */
  44.     if (pi->p_NumProjs > 0L)
  45.     {
  46.     PerfFunc (ai, NULL, "enable select remove", NULL);
  47.     }
  48.     else
  49.     {
  50.     PerfFunc (ai, NULL, "disable select remove", NULL);
  51.     }
  52.  
  53.     /* are we at the minimum? */
  54.     if (pi->p_CurLine <= 0)
  55.     {
  56.     pi->p_CurLine = 0;
  57.  
  58.     /* calling a function table entry using a command string */
  59.     PerfFunc (ai, NULL, "disable previous", NULL);
  60.     }
  61.     else
  62.     PerfFunc (ai, NULL, "enable previous", NULL);
  63.  
  64.     /* are we at the maximum? */
  65.     if (pi->p_CurLine >= (pi->p_NumProjs - 1))
  66.     {
  67.     pi->p_CurLine = (pi->p_NumProjs - 1);
  68.     PerfFunc (ai, NULL, "disable next", NULL);
  69.     }
  70.     else
  71.     PerfFunc (ai, NULL, "enable next", NULL);
  72.  
  73.     /* get the current project node */
  74.     if (pn = GetProjNode (ai, pi->p_CurLine, tl))
  75.     {
  76.     /* get the name and image for the current project so that we can
  77.      * display it. */
  78.     dob = pn->pn_DObj;
  79.     if (dob)
  80.         im = (struct Image *) dob->do_Gadget.GadgetRender;
  81.     name = pn->pn_ProjName;
  82.     }
  83.  
  84.     /*
  85.      * Always use APSHGetGadgetInfo to get a pointer to a gadget.  If the
  86.      * user closes the window and then reopens it, the gadget and window will
  87.      * have a different address.   OR perhaps the window is really not even
  88.      * open. */
  89.     if (APSHGetGadgetInfo (ai, "MAIN", "LIST", (ULONG *) & win, (ULONG *) & gad))
  90.     {
  91.     /* compute the top line --- shouldn't do when click in list */
  92.     if (pi->p_State == 1)
  93.     {
  94.         GT_SetGadgetAttrs (gad, win, NULL,
  95.                    GTLV_Selected, pi->p_CurLine,
  96.                    TAG_DONE);
  97.     }
  98.     else if (pi->p_State == 3)
  99.     {
  100.         pi->p_TopView = MAX ((pi->p_CurLine - 3L), 0L);
  101.  
  102.         GT_SetGadgetAttrs (gad, win, NULL,
  103.                    GTLV_Labels, list,
  104.                    GTLV_Selected, pi->p_CurLine,
  105.                    GTLV_Top, pi->p_TopView,
  106.                    TAG_DONE);
  107.     }
  108.     else
  109.     {
  110.         pi->p_TopView = MAX ((pi->p_CurLine - 3L), 0L);
  111.  
  112.         GT_SetGadgetAttrs (gad, win, NULL,
  113.                    GTLV_Selected, pi->p_CurLine,
  114.                    GTLV_Top, pi->p_TopView,
  115.                    TAG_DONE);
  116.     }
  117.     }
  118. }
  119.  
  120. /* Call before modifying a project list when it's attached to a Scrolling
  121.  * List */
  122. VOID BModListFunc (struct AppInfo * ai, STRPTR cmd, struct TagItem * tl)
  123. {
  124.     struct Gadget *gad;
  125.     struct Window *win;
  126.  
  127.     if (APSHGetGadgetInfo (ai, "MAIN", "LIST", (ULONG *) & win, (ULONG *) & gad))
  128.     {
  129.     /* You must set a Scrolling List label to ~0 before modifying it */
  130.     GT_SetGadgetAttrs (gad, win, NULL, GTLV_Labels, ~0, TAG_END);
  131.     }
  132. }
  133.  
  134. /* Call after modifying a project list. */
  135. VOID AModListFunc (struct AppInfo * ai, STRPTR cmd, struct TagItem * tl)
  136. {
  137.     struct Project *pi;
  138.  
  139.     /* default to the AppInfo Project structure */
  140.     pi = &(ai->ai_Project);
  141.  
  142.     /* see if there was a tag for a project list */
  143.     if (tl)
  144.     pi = (struct Project *) GetTagData (APSH_ProjInfo, (ULONG) pi, tl);
  145.  
  146.     /* total refresh */
  147.     pi->p_State = 3;
  148.  
  149.     /* refresh the view */
  150.     ShowProjectIcon (ai, cmd, tl);
  151. }
  152.  
  153. VOID NewFunc (struct AppInfo * ai, STRPTR cmd, struct TagItem * tl)
  154. {
  155.     STRPTR clone = NULL, argv[MAXARG], name = NULL;
  156.     ULONG argc = 0L;
  157.  
  158.     /*
  159.      * Turn off the list view.  How to call a function table entry using a
  160.      * function ID.
  161.      */
  162.     PerfFunc (ai, BModListID, NULL, tl);
  163.  
  164.     /* parse the command line */
  165.     clone = BuildParseLine (cmd, &argc, argv);
  166.  
  167.     /* make sure we have some arguments */
  168.     if (argc >= 2L)
  169.     {
  170.     /* get the name from the first argument [ZZZ: ignoring the rest]
  171.      * look at the remove function to see how to do multiple names */
  172.     name = argv[1];
  173.     }
  174.     else if (tl)
  175.     {
  176.     /* get the name from the name tag */
  177.     name = (STRPTR) GetTagData (APSH_NameTag, NULL, tl);
  178.     }
  179.  
  180.     /* create a new project */
  181.     NewProject (ai, name, tl);
  182.  
  183.     /* turn on the list view */
  184.     PerfFunc (ai, AModListID, NULL, tl);
  185.  
  186.     /* free the parsed line */
  187.     FreeParseLine (clone);
  188. }
  189.  
  190. VOID QuitFunc (struct AppInfo * ai, STRPTR cmd, struct TagItem * tl)
  191. {
  192.  
  193.     ai->ai_Done = TRUE;
  194. }
  195.  
  196. VOID OkayFunc (struct AppInfo * ai, STRPTR cmd, struct TagItem * tl)
  197. {
  198.  
  199.     ai->ai_Done = TRUE;
  200. }
  201.  
  202. VOID CancelFunc (struct AppInfo * ai, STRPTR cmd, struct TagItem * tl)
  203. {
  204.  
  205.     /* we're all done with this requester */
  206.     ai->ai_Done = TRUE;
  207. }
  208.  
  209. VOID PreviousFunc (struct AppInfo * ai, STRPTR cmd, struct TagItem * tl)
  210. {
  211.     struct Project *pi;
  212.  
  213.     /* default to the AppInfo Project structure */
  214.     pi = &(ai->ai_Project);
  215.  
  216.     /* see if there was a tag for a project list */
  217.     if (tl)
  218.     pi = (struct Project *) GetTagData (APSH_ProjInfo, (ULONG) pi, tl);
  219.  
  220.     /* make sure the current project is in the middle of the view */
  221.     pi->p_State = 2;
  222.  
  223.     /* move backwards through the list */
  224.     pi->p_CurLine--;
  225.  
  226.     /* display the project list */
  227.     ShowProjectIcon (ai, cmd, tl);
  228. }
  229.  
  230. VOID NextFunc (struct AppInfo * ai, STRPTR cmd, struct TagItem * tl)
  231. {
  232.     struct Project *pi;
  233.  
  234.     /* default to the AppInfo Project structure */
  235.     pi = &(ai->ai_Project);
  236.  
  237.     /* see if there was a tag for a project list */
  238.     if (tl)
  239.     pi = (struct Project *) GetTagData (APSH_ProjInfo, (ULONG) pi, tl);
  240.  
  241.     pi->p_State = 2;
  242.     pi->p_CurLine++;
  243.     ShowProjectIcon (ai, cmd, tl);
  244. }
  245.  
  246. VOID RemoveFunc (struct AppInfo * ai, STRPTR cmd, struct TagItem * tl)
  247. {
  248.     STRPTR clone = NULL, argv[MAXARG], name = NULL;
  249.     ULONG argc = 0L, cntri;
  250.  
  251.     /* turn off the list view */
  252.     PerfFunc (ai, BModListID, NULL, tl);
  253.  
  254.     /* parse the command line */
  255.     clone = BuildParseLine (cmd, &argc, argv);
  256.  
  257.     /* see if anything was passed in the command string */
  258.     if (argc >= 2L)
  259.     {
  260.     /* remove every name that was passed. */
  261.     for (cntri=1; cntri<argc; cntri++)
  262.         RemoveProject (ai, argv[cntri], tl);
  263.     }
  264.     else
  265.     {
  266.     if (tl)
  267.     {
  268.         /* see if a name was passed via a tag list */
  269.         name = (STRPTR) GetTagData (APSH_NameTag, NULL, tl);
  270.     }
  271.  
  272.     /* remove the current project */
  273.     RemoveProject (ai, name, tl);
  274.     }
  275.  
  276.     /* turn the list view back on */
  277.     PerfFunc (ai, AModListID, NULL, tl);
  278.  
  279.     /* free the built parse line */
  280.     FreeParseLine (clone);
  281. }
  282.  
  283. /* This is the basic SELECT function.  It doesn't incorporate the NEXT,
  284.  * PREVIOUS, TOP and BOTTOM keywords. */
  285. VOID SelectFunc (struct AppInfo * ai, STRPTR cmd, struct TagItem * tl)
  286. {
  287.     struct Project *pi;
  288.     struct Gadget *gad;
  289.     STRPTR name = NULL, clone=NULL, argv[MAXARG];
  290.     ULONG argc = 0L;
  291.  
  292.     /* default to the AppInfo Project structure */
  293.     pi = &(ai->ai_Project);
  294.  
  295.     /* parse the command string */
  296.     clone = BuildParseLine (cmd, &argc, argv);
  297.  
  298.     /* make sure we have some parameters to work with */
  299.     if (argc >= 2L)
  300.     {
  301.     name = argv[1];
  302.     }
  303.     else if (tl)
  304.     {
  305.     /* see if there was a tag for a project list */
  306.     pi = (struct Project *) GetTagData (APSH_ProjInfo, (ULONG) pi, tl);
  307.  
  308.     if (gad = (struct Gadget *) GetTagData (APSH_MsgIAddress, NULL, tl))
  309.         name = (STRPTR)(((struct StringInfo *)gad->SpecialInfo)->Buffer);
  310.     else
  311.         name = (STRPTR) GetTagData (APSH_NameTag, NULL, tl);
  312.     }
  313.  
  314.     /* make sure we have a name to select before continuing */
  315.     if (name)
  316.     {
  317.     struct ProjNode *pn;
  318.     struct List *list;
  319.  
  320.     /* get a pointer to our project list */
  321.     list = &(pi->p_ProjList);
  322.  
  323.     /* See if we can find the name in the project list.  Always use
  324.      * the case-insensitive FindNameI when searching AppShell lists. */
  325.     if (pn = (struct ProjNode *) FindNameI (list, name))
  326.     {
  327.         /* set the current project to the requested one */
  328.         pi->p_CurLine = pn->pn_ID;
  329.  
  330.         /* minor update */
  331.         pi->p_State = 3;
  332.  
  333.         /* update the view */
  334.         ShowProjectIcon (ai, cmd, tl);
  335.     }
  336.     }
  337.  
  338.     /* free the parsed line */
  339.     FreeParseLine (clone);
  340. }
  341.  
  342. /* This is the private function that gets called whenever the user selects
  343.  * the Scrolling List gadget */
  344. VOID ListFunc (struct AppInfo * ai, STRPTR cmd, struct TagItem * tl)
  345. {
  346.     struct Project *pi;
  347.  
  348.     /* default to the AppInfo Project structure */
  349.     pi = &(ai->ai_Project);
  350.  
  351.     /* see if there was a tag for a project list */
  352.     if (tl)
  353.     pi = (struct Project *) GetTagData (APSH_ProjInfo, (ULONG) pi, tl);
  354.  
  355.     pi->p_State = 1;
  356.  
  357.     /* get the current line */
  358.     pi->p_CurLine = GetTagData (APSH_MsgCode, NULL, tl);
  359.  
  360.     /* update the view */
  361.     ShowProjectIcon (ai, cmd, tl);
  362. }
  363.  
  364. /* this function is limited in that it only works from a ALT clicking in
  365.  * the Scrolling List gadget.  Should be set up to take its arguments from
  366.  * the command string as well as from a tag array */
  367. VOID SwapFunc (struct AppInfo * ai, STRPTR cmd, struct TagItem * tl)
  368. {
  369.     struct ProjNode *pn1, *pn2;
  370.     struct Project *pi;
  371.  
  372.     /* turn off the list view */
  373.     PerfFunc (ai, BModListID, NULL, tl);
  374.  
  375.     /* default to the AppInfo Project structure */
  376.     pi = &(ai->ai_Project);
  377.  
  378.     if (tl)
  379.     {
  380.     pi = (struct Project *) GetTagData (APSH_ProjInfo, (ULONG) pi, tl);
  381.     }
  382.  
  383.     /* get the current line */
  384.     pi->p_CurLine = GetTagData (APSH_MsgCode, NULL, tl);
  385.  
  386.     pn1 = pi->p_CurProj;
  387.     pn2 = GetProjNode (ai, pi->p_CurLine, tl);
  388.  
  389.     SwapProjNodes (ai, pn1, pn2, tl);
  390.  
  391.     /* turn on the list view */
  392.     PerfFunc (ai, AModListID, NULL, tl);
  393. }
  394.